package edu.ynu.se.xiecheng.achitectureclass.common.controller;


import edu.ynu.se.xiecheng.achitectureclass.common.dao.UserDao;
import edu.ynu.se.xiecheng.achitectureclass.common.entity.User;
import edu.ynu.se.xiecheng.achitectureclass.common.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping({"/user"})
public class UserController extends LogicController<UserService, UserDao, User, Long> {
    public UserController(@Autowired UserService service) {
        super(service);
    }

    @PostMapping
    public Boolean register(@RequestBody User entity) {
        return super.POST(entity) != null;
    }

    @PostMapping({"/login"})
    public Boolean login(@RequestBody Map<String, String> params) {
        System.out.println(params);
        String userName = (String)params.get("userName");
        String password = (String)params.get("password");
        return ((UserService)super.getService()).loginUser(userName, password);
    }
}
